package com.aaa.sas.service;

import com.aaa.sas.dao.ViewDao;
import com.aaa.pojo.test_result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Service
public class Serviceviewimpl implements Serviceview {
    @Autowired
    ViewDao viewDao;

    @Override
    public Map<String, Integer> findAllsas() {
        int normal = 0;
        int mild = 0;
        int moderate = 0;
        int severe = 0;
        List<test_result> viewSass = viewDao.findAllsas();
        for (test_result viewSas : viewSass){
            double forward = viewSas.getForward();
            double inversion = viewSas.getInversion();
            double sum = (forward + inversion) * 1.25;
            if (sum <= 50){
                ++normal;
            } else if (sum >= 50 && sum <= 59 ){
                ++mild;
            }else if (sum >= 60 && sum <= 69){
                ++moderate;
            }else {
                ++severe;
            }
        }
        Map<String, Integer> map = new HashMap<>();
        map.put("normal",normal);
        map.put("mild",mild);
        map.put("moderate",moderate);
        map.put("severe",severe);
        return map;
    }
}
